#!/bin/bash
#安装maven和jdk

#安装Java
installJavaAndMaven() {
    
    if  ! command -v git > /dev/null; then
        . ${currentDir}/dev/installAndConfigGit.sh
    fi

    if [ ! -d /home/${user}/dev/${jdk_dir} ]; then
        cd /home/${user}/dev
        git clone ${git_baseurl}${jdk_dir}".git" #下载jdk
        git clone ${git_baseurl}${maven_dir}".git" #下载maven
    fi

    if [ -d /home/${user}/dev/${jdk_dir} ]; then
        git pull
        impJavaHome=$(cat /home/${user}/.bash_path | grep JAVA_HOME)
        if [ -z "${impJavaHome}" ]; then
            echo "export JAVA_HOME=/home/${user}/dev/${jdk_dir}" >>/home/${user}/.bash_path
            echo "export JRE_HOME=\$JAVA_HOME/jre" >>/home/${user}/.bash_path
            echo "export CLASSPATH=.:\$JAVA_HOME/lib:\$JRE_HOME/lib:\$CLASSPATH" >>/home/${user}/.bash_path
            echo "export PATH=\$JAVA_HOME/bin:\$PATH" >>/home/${user}/.bash_path
            echo "" >>/home/${user}/.bash_path
        fi

        if [ -d /home/${user}/dev/${maven_dir} ]; then
            impMavenHome=$(cat /home/${user}/.bash_path | grep MAVEN_HOME)
            if [ -z "${impMavenHome}" ]; then
                echo "export MAVEN_HOME=/home/${user}/dev/${maven_dir}" >>/home/${user}/.bash_path
                echo "export PATH=\$MAVEN_HOME/bin:\$PATH" >>/home/${user}/.bash_path
                echo "" >>/home/${user}/.bash_path
            fi
        fi
    fi
    source /home/${user}/.bash_path
    if [ ! -d /home/${user}/project/java ]; then
        mkdir -p /home/${user}/project/java
    fi
    
}

installJavaAndMaven
